package com.yzh.list;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author 于振晗
 * @title: TestArrayList1
 * @description: TODO 集合测试
 * @date 2020年09月02日
 * @path com.yzh.list
 */
public class TestArrayList1 {
    public static void main(String[] args) {
        //创建List集合
        ArrayList list = new ArrayList();
        list.add(10);//添加元素
        list.add(1,100);
        list.add(20);
        list.add(10);
        System.out.println("集合长度为:"+list.size());

        System.out.println("+++++++++++++++++++++++++++");

        int elem = (int)list.get(1);
        System.out.println(elem);

        //元素遍历
        //for
        for (int i = 0; i < list.size(); i++) {
            System.out.println((int)list.get(i));
        }

        System.out.println("+++++++++++++++++++++++++++");

        //增强for
        for (Object o : list) {
            System.out.println((int)o);
        }


        System.out.println("+++++++++++++++++++++++++++");
        //迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        System.out.println("+++++++++++++++++++++++++++");

        //Lambda 表达式    JDK1.8新特性
        list.forEach((i)-> System.out.println(i));

        System.out.println("+++++++++++++++++++++++++++");

        list.forEach(System.out::println);

    }
}

